package com.example.hotelsystem.controller.userrolepower;


import code.CodeError;
import com.example.hotelsystem.entity.Role;
import com.example.hotelsystem.result.Result;
import com.example.hotelsystem.service.RoleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author Lee
 * @since 2020-10-13
 */
@RestController
@RequestMapping("/hotelsystem/role")
@Api(tags = "角色控制器")
public class RoleController {

    @Autowired
    RoleService roleService;

    @PostMapping("/list")
    @ApiOperation("查出该系统的所有角色")
    public Result PowerList(){
        List<Role> list = roleService.list();
        if(list!=null){
            return Result.success(list);
        }else{
            return Result.error(CodeError.ROLE_LIST_NULL,"角色list为空");
        }
    }

    @PostMapping("/add")
    @ApiOperation("新增角色")
    public Result addRole(Role role){
        try {
            roleService.save(role);
            return Result.success("操作成功");
        }catch (Exception e){
            return Result.error(e.getMessage());
        }
    }

}

